package coordinate

import (
	"io"
	"log"
	"net/http"
)

const url = "http://api.map.baidu.com/reverse_geocoding/v3/"

type Locale struct {
	Row string
	Col string
}

func city(location, style, ak string) ([]byte, error) {
	request, err := http.NewRequest(http.MethodGet, url, nil)
	if err != nil {
		log.Fatal("query topic failed", err.Error())
	}
	q := request.URL.Query()
	//"32.03805,120.275443"
	q.Add("location", location)
	q.Add("ak", ak)
	q.Add("output", style)
	q.Add("coordtype", "wgs84ll")
	request.URL.RawQuery = q.Encode()
	var resp *http.Response
	resp, err = http.DefaultClient.Do(request)
	if err != nil {
		log.Fatal("query topic failed", err.Error())
	}
	defer resp.Body.Close()
	return io.ReadAll(resp.Body)
}
